// pages/search_rim_detail/search_rim_detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
        types: 'jiudian',
        currenttab: '0',
        weizhi_imgUrl: '/icon/weizhi.png',
        path_imgUrl: '/icon/path.png',
        pinglun_name: '李艳梅',
        pinglun_time: '2020/10/1',
        pinglun_face: '/icon/touxiang.png',
        pinglun_imgUrl: '/icon/pinglun.png',
        pinglun_con: '推荐去!',
        id:'',
        city:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //拿到搜索传的type city id值
      this.setData({
        types:options.type,
        city:options.city,
        id:options.id
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: `https://wx.qasdwer.top:2001/search_rim_detail?type=${this.data.types}&city=${this.data.city}&id=${this.data.id}`,
      success:res=>{
        console.log(res.data)
        this.setData({
          list: res.data[0]
      })
      if (this.data.types == 'meishi') {
          let a = this.data.list.foodRecom;
          let a1 = a.substring(1, a.length - 1)
          let b = a1.split(',')
          for (let i = 0; i < b.length; i++) {
              b[i] = `(${i + 1})` + b[i].substring(1, b[i].length - 1)
          }
          this.setData({
              foodRecom: b
          })
      }
      },
      fail:err=>{
        console.error(err)
      }
    })
  },
  gotoRoute: function () {
    let endPoint
    let plugin = requirePlugin('routePlan');
    let key = 'HBABZ-QF7RX-C2S4W-TOZ4R-EQP66-UMB5X'; 
    let referer = 'i行亦知';   //调用插件的app的名称
    // console.log('122',this.data.info,this.data.type)
   if(this.data.types == 'jingdian'){
        console.log('2222')
        this.endPoint = JSON.stringify({  //终点
            'name': this.data.list.placeName,
            'latitude': this.data.list.latitude,
            'longitude': this.data.list.longitude
        });
    }
    console.log(this.endPoint)
    
    wx.navigateTo({
        url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + this.endPoint
    });
},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})